package sundial;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * Simple JUnit tests for Sundial Interface module.  Checks that different components are created
 * as expected.
 * 
 * @author Takanori Shiotsu
 * @author Reyn Matsumoto
 *
 */
public class SundialInterfaceTest{

	private SundialInterface tester;
	
	@Before
	public void setUp() throws Exception {
		tester = new SundialInterface();
	}

	@After
	public void tearDown() throws Exception {
		tester = null;
	}

	@Test
	public void testInit() {
		tester.init();
		
		assertNotNull("Cannot access gui.", tester.getGui());
		
		assertNotNull("Cannot access buttons.", tester.getButtons());
		assertEquals("Error.", 5, tester.getButtons().getComponentCount());
		
		assertNotNull("Cannot access inputs.", tester.getInputs());
		assertEquals("Error.", 4, tester.getInputs().getComponentCount());
		
		assertNotNull("Cannot access drawing.", tester.getDrawFrame());
		assertEquals("Error.", 1, tester.getDrawFrame().getComponentCount());
		
	}

	@Test
	public void testActionPerformed() {
		tester.init();
		
		tester.getTfDate().setText("01012000");
		assertEquals("Error in input field.", "01012000", tester.getTfDate().getText());
		
		tester.getTfLatitude().setText("45.0");
		assertEquals("Error in input field.", "45.0", tester.getTfLatitude().getText());
		
		tester.getTfLongitude().setText("90.0");
		assertEquals("Error in input field.", "90.0", tester.getTfLongitude().getText());
		
		tester.getCreateButton().doClick();
		assertNotNull("Cannot access drawing.", tester.getDrawing());
		
	}

	@Test
	public void testCreateSundial() {
		tester.init();
		
		tester.createSundial(45.0, 90.0, 01012000, false);
		assertNotNull("Error creating sundial.", tester.getComputations());
	}

}
